import pythoncom
import win32com.client

def test_connection():
    try:
        pythoncom.CoInitialize()
        acad = win32com.client.Dispatch("AutoCAD.Application.25")
        print(f"连接成功！版本：{acad.Version}")
        print(f"当前文档：{acad.ActiveDocument.Name}")
        return True
    except Exception as e:
        print(f"连接失败：{str(e)}")
        return False
    finally:
        pythoncom.CoUninitialize()

if __name__ == "__main__":
    test_connection()